package com.bdqn.business.academic.controller;

import com.bdqn.aop.Log;
import com.bdqn.business.academic.service.ExamService;
import com.bdqn.entity.academic.Exam;
import com.bdqn.entity.student.AskResult;
import com.bdqn.entity.student.UpperResult;
import com.bdqn.error.CommonException;
import com.bdqn.response.Result;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.ResultSet;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/exam")
public class ExamController {

    @Autowired
    private ExamService examService;

    @Log("获取教师端试卷列表")
    @RequestMapping(value = "/getExamList",method = RequestMethod.POST)
    public Result getExamList(@RequestBody Map<String,Object> map){
        return examService.getExamList(map);
    }


    @Log("教师端:保存试题")
    @RequestMapping(value = "/saveExam",method = RequestMethod.POST)
    public Result save(@RequestBody Map<String,Object> map) throws Exception {
        return examService.save(map);
    }

    /**开始考试前,确认考试状态没被定时器修改*/
    @Log("教师端:考试前确认考试状态没有被定时器修改")
    @RequestMapping(value = "/findById/{id}",method = RequestMethod.GET)
    public Result findById(@PathVariable("id")String id){
        return examService.findById(id);
    }

    @Log("教师端:开始考试")
    @RequestMapping(value = "/start",method = RequestMethod.POST)
    public Result start(@RequestBody Exam exam){
        return examService.start(exam);
    }

    @Log("教师端:监控答题")
    @RequestMapping(value = "/getStudentScoreListByExam",method = RequestMethod.POST)
    public Result getStudentScoreListByExam(@RequestBody Exam exam){
        return examService.getStudentScoreListByExam(exam);
    }

    @Log("教师端:手动停止考试")
    @RequestMapping(value = "/stopExam",method = RequestMethod.POST)
    public Result stopExam(@RequestBody Exam exam){
        return examService.stopExam(exam);
    }


    @Log("教师端:获得该试卷所有学生的问答题")
    @RequestMapping(value = "/getStudentAskResultList",method = RequestMethod.POST)
    public Result getStudentAskResultList(@RequestBody Exam exam){
        return examService.getStudentAskResultList(exam);
    }

    @Log("教师端:给学生的问答题判分")
    @RequestMapping(value = "/updateStudentAskScore",method = RequestMethod.POST)
    public Result updateStudentAskScore(@RequestBody List<AskResult> list) throws CommonException {
        return examService.updateStudentAskScore(list);
    }

    @Log("教师端:获得该试卷所有学生的上机题")
    @RequestMapping(value = "/getStudentUpperResultList",method = RequestMethod.POST)
    public Result getStudentUpperResultList(@RequestBody Exam exam){
        return examService.getStudentUpperResultList(exam);
    }

    @Log("教师端:给学生的上机题判分")
    @RequestMapping(value = "/updateStudentUpperScore",method = RequestMethod.POST)
    public Result updateStudentUpperScore(@RequestBody List<UpperResult> list) throws CommonException {
        return examService.updateStudentUpperScore(list);
    }

    @Log("教师端:结束考试")
    @RequestMapping(value = "/overExam",method = RequestMethod.POST)
    public Result overExam(@RequestBody Exam exam){
        return examService.overExam(exam);
    }

    @Log("教师端：获得未参考，未批阅上机题，未批阅问答题人员名单")
    @RequestMapping(value = "/handleNotPerson",method = RequestMethod.POST)
    public Result handleNotPerson(@RequestBody Exam exam){
        return examService.handleNotPerson(exam);
    }

    @Log("教师端：执行某个学生某个试卷无需参考")
    @RequestMapping(value = "/notConsult",method = RequestMethod.POST)
    public Result notConsult(@RequestBody Map<String,Object> map){
        return examService.notConsult(map.get("examId").toString(),map.get("studentId").toString());
    }

    @Log("教师端：试卷分析,图表数据")
    @RequestMapping(value = "/analysisExam",method = RequestMethod.POST)
    public Result analysisExam(@RequestBody Exam exam){
        return examService.analysisExam(exam);
    }


    @Log("教师端：试卷讲解")
    @RequestMapping(value = "/explainExam",method = RequestMethod.POST)
    public Result explainExam(@RequestBody Exam exam){
        return examService.explainExam(exam);
    }

    @Log("教师端：日测,周测,月考 成绩监测")
    @RequestMapping(value = "/superviseExam",method = RequestMethod.POST)
    public Result superviseExam(@RequestBody Map<String,Object> map) throws ParseException {
        return examService.superviseExam(map);
    }

}
